package com.olt.domain.oltCenter.problem;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
public class BlanksProblem extends ProblemAbstract{
    List<Blank> blankData;


    @Override
    public void deleteAns() {
        for (Blank blankDatum : blankData) {
            blankDatum.setAns("");
        }
    }

    @Override
    public Double getScore(Integer score, JSONObject jsonObject){
        List<String> res =jsonObject.getJSONArray("res").toJavaList(String.class);
        double right=0.0;
        int idx=0;
        for(var i :blankData){
            var ans=res.get(idx++);
            if(i.isMatches&& i.getAns().contains(ans)){
                right++;
            }
            if(!i.isMatches&&i.getAns().equals(ans)){
                right++;
            }

        }
        return  score*right/res.size();
    }
}
@Setter
@Getter
 class Blank{
    public Boolean isMatches;

    public String ans;

}

